#include <iostream>
#include <cstring>
#include <algorithm>

using namespace std;

const int N = 210;

int n;
int dp[N][N];
int w[N];

int main()
{
    cin >> n;
    for (int i = 1; i <= n; i ++ )
    {
        cin >> w[i];
        w[i + n] = w[i];
    }
    
    for (int len = 3; len <= n + 1; len ++ )
        for (int l = 1; l + len - 1 <= n * 2; l ++ )
        {
            int r = l + len - 1;
            for (int k = l + 1; k < r; k ++ )
                dp[l][r] = max(dp[l][r], dp[l][k] + dp[k][r] + w[l] * w[r] * w[k]);
        }
    int res = 0;
    for (int i =1; i <= n; i ++ ) res = max(res, dp[i][i + n]);
    cout << res << endl;
    return 0;
}
